#version 330 core

out vec4 FragColor;

uniform vec2 iResolution;
uniform float iTime;

float sdRoundBox( vec2 position, vec2 b, vec4 radius)
{
    radius.xy = (position.x>0.0)?radius.xy : radius.zw;
    radius.x  = (position.y>0.0)?radius.x  : radius.y;
    vec2 q = abs(position)-b+radius.x;
    return min(max(q.x,q.y),0.0) + length(max(q,0.0)) - radius.x;
}

void mainImage(out vec4 fragColor, vec2 fragCoord)
{
    vec2 uv = fragCoord/iResolution.xy;

    vec2 position = (2.0* fragCoord - iResolution.xy) / iResolution.xy;

    //cos(vec2(0,2)) [1,-0.416147]
    //0.3*cos(vec2(0,2)) [0.3,-0.1248441]
    vec2 si = vec2(0.9,0.6) + 0.3*cos(vec2(0,2)); // [1.2, 0.4751559]
    //vec4(0,1,2,3) [1, 0.540302, -0.416147, -0.989992]
    vec4 radius = 0.3 + 0.3*cos( + vec4(0,1,2,3) );
    radius = min(radius,min(si.x,si.y));

    float distance = sdRoundBox(position, si, radius);

    vec3 color = ( distance > 0.0) ? vec3(0.9, 0.6, 0.3) : vec3(0.65, 0.85, 1.0);

//    vec4 a = vec4(1,1,1,0);
//    color = vec3(a.w);
    // Output to screen
    fragColor = vec4(color, 1.0);
}

void main()
{
    vec4 fragColor;
    mainImage(fragColor, gl_FragCoord.xy);

    FragColor = fragColor;
}
